// components/common/user-agreement/index.js
import componentBehavior from '../../../behaviors/component';
import { COMPONENT_OPTIONS } from '../../../constants/common';
import { getMenuButtonBoundingClientRect } from '../../../common/env';
import { getConfig } from '../../../api/common';

Component({
    behaviors: [componentBehavior],
    options: {
        ...COMPONENT_OPTIONS,
    },
    properties: {
        show: {
            type: Boolean,
            value: false,
        },
        containsHeader: {
            type: Boolean,
            value: true,
        },
    },
    lifetimes: {
        attached() {
            const rect = getMenuButtonBoundingClientRect();
            const { containsHeader } = this.data;
            this.setData({
                styleValue: `padding-top: ${containsHeader ? rect.bottom + 10 : rect.top}px;`,
            });
        },
    },
    observers: {
        'show': function(show) {
            if (show) {
                getConfig(true).then(res => {
                    const htmlSnip = res.agreementHtml;
                    this.setData({ htmlSnip });
                })
            }
        },
    },
    data: {
        htmlSnip: '',
    },
    methods: {
        handleClose() {
            this.setData({
                show: false,
            });
            // this.triggerEvent('close');
        },
    }
})
